/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-04-09
 * Time: 13:28
 */
class Waittest implements Runnable {
    private Object locker = null;
    public Waittest (Object locker) {
        this.locker = locker;
    }
    @Override
    public void run() {
        //等待的线程
        synchronized (locker) {
            System.out.println("等待开始");
            try {
                locker.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("等待结束");
        }
    }
}

class Notify implements Runnable {
    private Object locker = null;
    public Notify (Object locker) {
        this.locker = locker;
    }
    //唤醒的线程
    @Override
    public void run() {
        synchronized (locker) {
            System.out.println("开始唤醒");
            locker.notify();
            System.out.println("结束唤醒");
        }
    }
}
public class Test03 {
    public static void main(String[] args) throws InterruptedException {
        Object lock = new Object();
        Thread t1 = new Thread( new Waittest(lock));
        Thread t2 = new Thread (new Notify(lock));
        t1.start();
        Thread.sleep(2000);
        t2.start();
    }
}
